import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class Securestorage {
  static final _instance = Securestorage._internal();
  static final FlutterSecureStorage _storage = FlutterSecureStorage();

  factory Securestorage() => _instance;

  Securestorage._internal();

  // 存储敏感数据（如令牌）
  static Future<void> save(String key, String value) async {
    try {
      await _storage.write(key: key, value: value);
    } catch (e) {
      print('安全存储失败：$e');
    }
  }

  // 获取敏感数据
  static Future<String?> get(String key) async {
    try {
      return await _storage.read(key: key);
    } catch (e) {
      print('获取安全存储失败：$e');
      return null;
    }
  }

  // 删除敏感数据
  static Future<void> delete(String key) async {
    try {
      await _storage.delete(key: key);
    } catch (e) {
      print('删除安全存储失败：$e');
    }
  }
}
